package com.webmagic.webmagic.controller;

import com.webmagic.webmagic.service.RestTemplateService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author xbl
 * @Description
 * @date 2019/1/4
 */
@Api(description = "restTemplate的controller")
@RestController
@RequestMapping("/restTemplate")
public class RestTemplateController {

    @Autowired
    private RestTemplateService restTemplateService;

    @ApiOperation("测试json")
    @RequestMapping(value = "/test", method = RequestMethod.GET)
    public String test(@RequestParam("url") String url) {
        return restTemplateService.test(url);
    }

    @ApiOperation("测试返回图片")
    @RequestMapping(value = "/picture", method = RequestMethod.GET)
    public void picture(HttpServletResponse response, @RequestParam("url") String url) {
        restTemplateService.picture(response, url);
    }

    @ApiOperation("测试爬取")
    @RequestMapping(value = "/start", method = RequestMethod.GET)
    public void start() {
        restTemplateService.start();
    }
}
